home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 1 / QRZ Ham Radio Callsign Database - December 1993.iso / ucsd / packet / tcpip / sys5 / iscwmpst.z / iscwmpst / tcp / src / asy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-10  |  4.8 KB  |  215 lines

  1. /* @(#) $Header: asy.c,v 1.4 91/05/09 07:37:59 deyke Exp $ */
  2.  
  3. /* Generic serial line interface routines
  4.  * Copyright 1991 Phil Karn, KA9Q
  5.  */
  6. #include <stdio.h>
  7. #include "global.h"
  8. #include "config.h"
  9. #include "proc.h"
  10. #include "iface.h"
  11. #include "netuser.h"
  12. /* #include "slhc.h" */
  13. #include "8250.h"
  14. #include "asy.h"
  15. #include "ax25.h"
  16. #include "kiss.h"
  17. #include "nrs.h"
  18. #include "pktdrvr.h"
  19. #include "slip.h"
  20. /* #include "ppp.h" */
  21. #include "commands.h"
  22.  
  23. /* Attach a serial interface to the system
  24.  * argv[0]: hardware type, must be "asy"
  25.  * argv[1]: I/O address, e.g., "0x3f8"
  26.  * argv[2]: vector, e.g., "4"
  27.  * argv[3]: mode, may be:
  28.  *              "slip" (point-to-point SLIP)
  29.  *              "ax25" (AX.25 frame format in SLIP for raw TNC)
  30.  *              "nrs" (NET/ROM format serial protocol)
  31.  *              "ppp" (Point-to-Point Protocol, RFC1171, RFC1172)
  32.  * argv[4]: interface label, e.g., "sl0"
  33.  * argv[5]: receiver ring buffer size in bytes
  34.  * argv[6]: maximum transmission unit, bytes
  35.  * argv[7]: interface speed, e.g, "9600"
  36.  * argv[8]: optional flags,
  37.  *              'c' for cts flow control;
  38.  *              'r' for RLSD (RS232 pin 8, CD) physical link up/down;
  39.  *              'v' for Van Jacobson TCP header compression (SLIP only,
  40.  *                  use ppp command for VJ compression with PPP);
  41.  */
  42. int
  43. asy_attach(argc,argv,p)
  44. int argc;
  45. char *argv[];
  46. void *p;
  47. {
  48.     register struct iface *ifp;
  49.     struct asy *asyp;
  50.     int dev;
  51.     int xdev;
  52.     int trigchar = -1;
  53.     char cts = FALSE;
  54.     char rlsd = FALSE;
  55. #if     defined(SLIP) || defined(AX25)
  56.     struct slip *sp;
  57. #endif
  58. #ifdef  NRS
  59.     struct nrs *np;
  60. #endif
  61.  
  62.     if(if_lookup(argv[4]) != NULLIF){
  63.         tprintf("Interface %s already exists\n",argv[4]);
  64.         return -1;
  65.     }
  66.     /* Find unused asy control block */
  67.     for(dev=0;dev < ASY_MAX;dev++){
  68.         asyp = &Asy[dev];
  69.         if(asyp->iface == NULLIF)
  70.             break;
  71.     }
  72.     if(dev >= ASY_MAX){
  73.         tprintf("Too many asynch controllers\n");
  74.         return -1;
  75.     }
  76.  
  77.     /* Create interface structure and fill in details */
  78.     ifp = (struct iface *)callocw(1,sizeof(struct iface));
  79.     ifp->addr = Ip_addr;
  80.     ifp->name = strdup(argv[4]);
  81.     ifp->mtu = atoi(argv[6]);
  82.     ifp->dev = dev;
  83.     ifp->stop = asy_stop;
  84.  
  85. #ifdef  SLIP
  86.     if(stricmp(argv[3],"SLIP") == 0) {
  87.         for(xdev = 0;xdev < SLIP_MAX;xdev++){
  88.             sp = &Slip[xdev];
  89.             if(sp->iface == NULLIF)
  90.                 break;
  91.         }
  92.         if(xdev >= SLIP_MAX) {
  93.             tprintf("Too many slip devices\n");
  94.             return -1;
  95.         }
  96.         setencap(ifp,"SLIP");
  97.         ifp->ioctl = asy_ioctl;
  98.         ifp->raw = slip_raw;
  99.         ifp->status = slip_status;
  100.         ifp->flags = 0;
  101.         ifp->xdev = xdev;
  102.  
  103.         sp->iface = ifp;
  104.         sp->send = asy_send;
  105.         sp->get = get_asy;
  106.         sp->type = CL_SERIAL_LINE;
  107.         trigchar = FR_END;
  108. #ifdef VJCOMPRESS
  109.         if((argc > 8) && (strchr(argv[8],'v') != NULLCHAR)) {
  110.             sp->escaped |= SLIP_VJCOMPR;
  111.             sp->slcomp = slhc_init(16,16);
  112.         }
  113. #else
  114.         sp->slcomp = NULL;
  115. #endif  /* VJCOMPRESS */
  116.         ifp->rxproc = asy_rx;
  117.     } else
  118. #endif
  119. #ifdef  AX25
  120.     if(stricmp(argv[3],"AX25") == 0) {
  121.         /* Set up a SLIP link to use AX.25 */
  122.         for(xdev = 0;xdev < SLIP_MAX;xdev++){
  123.             sp = &Slip[xdev];
  124.             if(sp->iface == NULLIF)
  125.                 break;
  126.         }
  127.         if(xdev >= SLIP_MAX) {
  128.             tprintf("Too many slip devices\n");
  129.             return -1;
  130.         }
  131.         setencap(ifp,"AX25");
  132.         ifp->ioctl = kiss_ioctl;
  133.         ifp->raw = kiss_raw;
  134.         ifp->status = slip_status;
  135.  
  136.         if(ifp->hwaddr == NULLCHAR)
  137.             ifp->hwaddr = mallocw(AXALEN);
  138.         memcpy(ifp->hwaddr,Mycall,AXALEN);
  139.         ifp->xdev = xdev;
  140.  
  141.         sp->iface = ifp;
  142.         sp->send = asy_send;
  143.         sp->get = get_asy;
  144.         sp->type = CL_KISS;
  145.         trigchar = FR_END;
  146.         ifp->rxproc = asy_rx;
  147.     } else
  148. #endif
  149. #ifdef  NRS
  150.     if(stricmp(argv[3],"NRS") == 0) {
  151.         /* Set up a net/rom serial iface */
  152.         for(xdev = 0;xdev < SLIP_MAX;xdev++){
  153.             np = &Nrs[xdev];
  154.             if(np->iface == NULLIF)
  155.                 break;
  156.         }
  157.         if(xdev >= SLIP_MAX) {
  158.             tprintf("Too many nrs devices\n");
  159.             return -1;
  160.         }
  161.         /* no call supplied? */
  162.         setencap(ifp,"AX25");
  163.         ifp->ioctl = asy_ioctl;
  164.         ifp->raw = nrs_raw;
  165.  
  166.         ifp->hwaddr = mallocw(AXALEN);
  167.         memcpy(ifp->hwaddr,Mycall,AXALEN);
  168.         ifp->xdev = xdev;
  169.         np->iface = ifp;
  170.         np->send = asy_send;
  171.         np->get = get_asy;
  172.         trigchar = ETX;
  173.         ifp->rxproc = nrs_recv;
  174.     } else
  175. #endif
  176. #ifdef  PPP
  177.     if(stricmp(argv[3],"PPP") == 0) {
  178.         /* Setup for Point-to-Point Protocol */
  179.         trigchar = HDLC_FLAG;
  180.         setencap(ifp,"PPP");
  181.         ifp->ioctl = asy_ioctl;
  182.         ifp->flags = FALSE;
  183.  
  184.         /* Initialize parameters for various PPP phases/protocols */
  185.         if((argc > 8) && (strchr(argv[8],'r') != NULLCHAR))
  186.             rlsd = TRUE;
  187.  
  188.         if (ppp_init(ifp) != 0) {
  189.             tprintf("Cannot allocate PPP control block\n");
  190.             free(ifp->name);
  191.             free((char *)ifp);
  192.             return -1;
  193.         }
  194.     } else
  195. #endif
  196.     {
  197.         tprintf("Mode %s unknown for interface %s\n",
  198.             argv[3],argv[4]);
  199.         free(ifp->name);
  200.         free(ifp);
  201.         return -1;
  202.     }
  203.  
  204.     /* Link in the interface */
  205.     ifp->next = Ifaces;
  206.     Ifaces = ifp;
  207.  
  208.     if((argc > 8) && (strchr(argv[8],'c') != NULLCHAR))
  209.         cts = TRUE;
  210.  
  211.     asy_init(dev,ifp,argv[1],argv[2],(int16)atol(argv[5]),
  212.         trigchar,cts,rlsd,(int16)atol(argv[7]));
  213.     return 0;
  214. }
  215.